<?php
/*
*日志接口类
*/
class logAppClass extends app{
	/*查询条件*/
	public function search(){
		//权限
		if($this->power("log","seeAll")){
			$stid = "是";
		}else{
			$stid = "否";
		}
		//查询条件
		$json['search'] = array(
			"stid" => $stid,//查看所有
		);
		//提示
		$json['warn'] = "success";
		//返回
		return $json;
	}
	/*系统设置-系统日志-列表页*/
	public function home(){
		//like查询数组
		$like = array(
			"text" => $this->post['text'],//详细说明
		);
		//全等查询数组
		$equal = array(
			"stid" => $this->post['stid'],//目标对象
		);
		$and = "";
		//导航
		if(!empty($this->post['powerOne'])){
			if(empty($this->post['powerTwo'])){
				$powerOne = $this->post['powerOne'];
				$and .= " and type in ( '".implode("','",array_keys($this->powerAll[$powerOne]))."' ) ";
			}else{
				$and .= " and type = '".$this->post['powerTwo']."' ";
			}
		}
		//发生时间-开始日期
		if(!empty($this->post['startDay'])){
			$startDay = $this->post['startDay']." 00:00:00";
			$and .= " and time >= '$startDay' ";
		}
		//记录时间-结束日期
		if(!empty($this->post['endDay'])){
			$endDay = $this->post['endDay']." 23:59:59";
			$and .= " and time <= '$endDay' ";
		}
		//如果没有查看所有员工账户记录的权限
		if(!$this->power("log","seeAll")){
			$and .= " and stid = '".$this->control['stid']."' ";
		}
		//获取查询结果
		$where = search(array("like" => $like,"=" => $equal)).$and;
		$page = $this->page(array("table" => "log","where" => $where,"order" => "time desc"));
		//数据分析
		$json['log'] = array();
		foreach($page['array'] as $array){
			$staff = query("staff","stid = '$array[stid]'");
			$menuOne = $menuTwo = "";
			foreach($this->powerAll as $key => $value){
				if(!empty($value[$array['type']]['name'])){
					$menuOne = $key;
					$menuTwo = $value[$array['type']]['name'];
				}
			}
			$json['log'][] = array(
				"staffName" => $staff['name'],//员工
				"type" => $menuOne."-".$menuTwo,//分类
				"text" => $array['text'],//内容
				"time" => $array['time'],//时间
			);
		}
		//返回
		$json['page'] = $page['para'];
		$json['warn'] = "success";
		return $json;
	}
	
}
?>